package org.agile2soft.nexoma.core.entity;

import java.util.HashSet;
import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import static javax.persistence.GenerationType.IDENTITY;

import javax.persistence.CascadeType;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Table;

@Entity
@Table(name = "SERVICE_GROUP")
public class ServicesGroup implements java.io.Serializable {

    private Integer id;
    private String name;
    private String url;
    private Set<Service> services = new HashSet<Service>(0);


    public ServicesGroup () {
    }

    public ServicesGroup(String name, String url) {
        this.name = name;
        this.url = url;
    }

    public ServicesGroup(String name,String url, Set<Service>services) {
        this(name,url);
        this.services = services;
    }


    public String toString() {
        return String.format("[ServiceGroup %s,%s,%s]",id,name,url);
    }

    @Id
    @GeneratedValue(strategy=IDENTITY)
    @Column(name="SEG_ID", nullable=false, unique=true)
    public Integer getId() {
        return this.id;
    }

    public void setId(Integer id) {
        this.id=id;
    }

    @Column( name="SEG_NAME", nullable=false, unique=true )
    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @Column( name="SEG_URL", unique=true,nullable=false, updatable=true,insertable=true)
    public String getUrl() {
        return url;
    }

    public void setUrl(String url) {
        this.url = url;
    }

    @OneToMany(fetch = FetchType.LAZY, mappedBy = "group",cascade=CascadeType.ALL)
    public Set<Service> getServices() {
        return this.services;
    }

    public void setServices(Set<Service> services) {
        this.services=services;
    }

}
